package com.sinothk.client.user.controller;

import com.sinothk.client.user.entity.UserEntity;
import com.sinothk.client.user.service.impl.UserService;
import com.sinothk.server.support.author.AuthorCheck;
import com.sinothk.server.support.entity.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户操作")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService userService;

    @ApiOperation(value = "新增用户", notes = "新增用户")
    @AuthorCheck
    @PostMapping("/add")
    public ResultData<UserEntity> add(
            @ApiParam(value = "用户名", required = true) @RequestParam("name") String name) {
//        String ownerAccount = TokenUtil.getTokenValue(token, "account");
        UserEntity user = new UserEntity();
        user.setUserName(name);
        return new ResultData<UserEntity>().getSuccess(user);
    }

    @ApiOperation(value = "获取用户", notes = "获取用户")
    @GetMapping("/getInfo")
    public ResultData<UserEntity> getInfo(@ApiParam(value = "验证Token", type = "header", required = true) @RequestHeader(value = "token") String token) {
        UserEntity user = new UserEntity();
        user.setUserName(userService.hiService("1111"));
        ResultData<UserEntity> resultData = new ResultData<>();
        resultData.setData(user);
        return resultData;
    }

    @ApiOperation(value = "获取鉴权11", notes = "获取鉴权11。。")
    @GetMapping("/getInfo2")
    public ResultData<UserEntity> getInfo2() {
        UserEntity user = new UserEntity();
        user.setUserName("sinothk");
        ResultData<UserEntity> resultData = new ResultData<>();
        resultData.setData(user);
        return resultData;
    }
}
